#include "GameMenuState.h"

GameMenuState::GameMenuState(BeanieCore* a_core, bool a_renew)
{
	m_core = a_core;

	m_name = "GameMenu";
	m_selfId = GAMEMENU;
	m_swapId = GAMEMENU;
	m_completed = false;
	m_renew = a_renew;
}

void GameMenuState::init()
{
	//init the textures for GameTexture and GameButton
	//GameButton inherits from GameTexture so init() calls are the same
	m_titleTex.initTexture(m_core,BG_TITLE,
		TEX_TOPLEFT,V2D_ZERO,V2D_DOUBLE,0.0f,true);
	m_playBtn.initTexture(m_core,BTN_PLAY,
		TEX_TOPLEFT,V2DF(250,500),V2D_ONES,0.0f,true);
	m_optionBtn.initTexture(m_core,BTN_OPTIONS,
		TEX_TOPLEFT,V2DF(540,500),V2D_ONES,0.0f,true);
	m_quitBtn.initTexture(m_core,BTN_EXIT,
		TEX_TOPLEFT,V2DF(910,500),V2D_ONES,0.0f,true);

	//init the GameButtons onClick() action
	//takes in a Lambda Expression that indicates what to do when the button is click
	//in this case, it sets the state to the desire state and trigger the state to
	//be in completed state which is checked by the system for swapping to the given swapId
	m_playBtn.onClick([&](){m_swapId=GAMEPLAY;m_completed=true;});
	m_optionBtn.onClick([&](){m_swapId=GAMEOPTIONS;m_completed=true;});
	m_quitBtn.onClick([&](){m_swapId=GAMEQUIT;m_completed=true;});
}

void GameMenuState::release()
{

}

void GameMenuState::input()
{
	//call the GameButtons input()
	//the input() is a GameTexture function so it can be used for it
	//the input() will check if the button is being hover or clicked
	m_playBtn.input();
	m_optionBtn.input();
	m_quitBtn.input();

	if(m_core->keyPress(KEY_ESCAPE))
	{
		m_swapId = GAMEQUIT;
		m_completed = true;
	}
}

void GameMenuState::update()
{
	//call GameTexture and GameButton update()
	//GameTexture update() updates the texture transformation
	//GameButton update() calls the GameTexture update()
	//and runs the onClick() and onHover() action if triggered
	m_titleTex.update();
	m_playBtn.update();
	m_optionBtn.update();
	m_quitBtn.update();
}

void GameMenuState::draw()
{
	//call GameTexture and GameButton draw()
	//GameButton inherits the draw() from GameTexture
	//and is not overwritten, so it does the same
	//used to draw the sprite; update() and draw()
	//needs to be used together to work properly
	m_titleTex.draw();
	m_playBtn.draw();
	m_optionBtn.draw();
	m_quitBtn.draw();
}

void GameMenuState::preLoop()
{
	
}

void GameMenuState::postLoop()
{

}